package net.expectx.pay.rpc.service.impl;

import com.google.common.collect.Maps;
import net.expectx.common.single.base.BaseConstants;
import net.expectx.common.single.base.BaseServiceImpl;
import net.expectx.pay.dao.bean.MerchantUser;
import net.expectx.pay.dao.mapper.MerchantOauthMapper;
import net.expectx.pay.dao.bean.MerchantOauth;
import net.expectx.pay.dao.mapper.MerchantUserMapper;
import net.expectx.pay.rpc.api.MerchantOauthService;
import net.expectx.pay.dao.bean.MerchantOauthExample;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * MerchantOauthService实现
 * @author lijian
 * @date 2019/7/11
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MerchantOauthServiceImpl extends BaseServiceImpl<MerchantOauth, MerchantOauthExample> implements MerchantOauthService {

    private static final Logger LOGGER = Logger.getLogger(MerchantOauthServiceImpl.class);

    @Autowired
    MerchantOauthMapper merchantOauthMapper;
    @Autowired
    MerchantUserMapper merchantUserMapper;

    @Override
    public Map<String, Object> lookMerchantOauthStatus(Long merchantUserId) {
        Map<String,Object>resultData= Maps.newHashMapWithExpectedSize(7);
        MerchantUser merchantUser=merchantUserMapper.selectByPrimaryKey(merchantUserId);
        resultData.put("isAuth",merchantUser.getIsAuth()==BaseConstants.YES?true:false);
        if (merchantUser.getIsAuth()!= BaseConstants.YES){
            MerchantOauthExample merchantOauthExample = new MerchantOauthExample();
            MerchantOauthExample.Criteria criteria = merchantOauthExample.createCriteria();
            criteria.andMerchantUserIdEqualTo(merchantUser.getId());
            List<MerchantOauth> merchantOauthList = merchantOauthMapper.selectByExample(merchantOauthExample);
            if(!merchantOauthList.isEmpty()){
                MerchantOauth merchantOauth = merchantOauthList.get(0);
                resultData.put("status",merchantOauth.getStatus());
                resultData.put("message",merchantOauth.getOauthRemark());

            }else{
                resultData.put("status",-1);
                resultData.put("message","未认证");
            }

        }
        return resultData;
    }
}
